# @coding utf-8
# @author errorcpp@qq.com
#
# 1.xtrans_to_absolute_path 相对路径转为绝对路径
# 2.xtrans_to_relative_path 绝对路径转为相对路径

# 相对路径转绝对路径
# SRC_PATH：  ${test_path},变量方式传入
# DST_PATH:   absolute_path,变量名方式传入
function(xtrans_to_absolute_path SRC_PATH DST_PATH)
    #message("trans1:" ${SRC_PATH})
    if(NOT IS_ABSOLUTE "${SRC_PATH}")
        set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_PATH}")
    endif()
    #message("trans2:" ${SRC_PATH})
    get_filename_component(absolute_path "${SRC_PATH}" ABSOLUTE)
    #message("trans3:" ${absolute_path})
    set(${DST_PATH} "${absolute_path}" PARENT_SCOPE)
    #message("trans4:" ${DST_PATH})
endfunction()
#
# set(test_path "./../a/b/c.cc")
# set(absolute_path)
# xtrans_to_absolute_path(${test_path} absolute_path)

# 绝对路径转相对路径
function(xtrans_to_relative_path SRC_PATH DST_PATH)
  if(NOT IS_ABSOLUTE "${SRC_PATH}")
    set(${DST_PATH} "${SRC_PATH}")
  else()
    file(RELATIVE_PATH TMP_DST_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${SRC_PATH}")
  endif()
  set(${DST_PATH} "${TMP_DST_PATH}" PARENT_SCOPE)
endfunction()